package com.sun.jedis;

import redis.clients.jedis.Jedis;

import java.util.Set;

public class jedis1 {
    public static void main(String[] args) {
        //1
//        String URL = "127.0.0.1";
        String URL = "192.168.1.103";
        Integer port = 6379;
        Jedis jedis = new Jedis(URL,port);
        //测试能否连接到
        String value = jedis.ping();
        System.out.println(value);
        jedis.set("k1","v1");
        jedis.set("k2","v2");
        jedis.set("k3","v3");
        Set<String> keys = jedis.keys("*");
        for (String key : keys) {
            if (jedis.exists(key)){
                System.out.println("k " + key + "的值为" + jedis.get(key));
                String msg = "";
                if (jedis.ttl(key)==-1){
                    msg = "永不过期";
                }else if (jedis.ttl(key)==-2){
                    msg = "已经过期了";
                }else {
                    msg = String.valueOf(jedis.ttl(key));
                }

                System.out.println("k " + key + "的过期时间:" + msg);
            }
        }
//        String s = jedis.flushDB();
//        System.out.println(s);
    }
}
